Remove() not working on new elements [duplicate]

Posted by user3317470 on Stack Overflow See other posts from Stack Overflow or by user3317470
Published on 2014-08-21T04:16:23Z Indexed on 2014/08/21 4:20 UTC
Read the original article Hit count: 61

Filed under:
|

This question already has an answer here:

I'm making a simple to do list. It's mostly working and finished. When you click on list elements the object gets removed and you can create new list elements through the text input at the bottom. The only problem is the new list elements can't be removed when you click them for some reason.

Here's the code:

http://jsfiddle.net/dnhynh/7psqndwL/20/

$(document).ready(function(){

    $("li").click(function(){
        $(this).remove();
    });

    $("button").click(function(){
        var entry = $("#entry").val();
        $("<li></li>", {
            text: entry
        }).appendTo("#list ul");   
        $("#entry").val("");
    });

});

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery